<template>
    <div>
        <div @click="signIn" :class="{signIn:flag ==true}" v-if="flag==true">签到啦, 请点我!</div>
    </div>
</template>

<script>
    export default {
        props: ['websockMsg'],
        data() {
            return {
                flag: false,
            }
        },
        created () {
            if (this.websockMsg.type == 4) {
                this.flag = true;
            }else if(this.websockMsg.type == 8){
                this.flag = false
            }
        },
        methods: {
            signIn() {
                let self = this;
                self.$http.get("/tes/attendance/record").then(response => {
                    let res = response.data;
                    if (res.code == "200") {
                        self.$message({
                            message: "签到成功",
                            type: "success"
                        });
                        self.flag = false;
                        // self.InitWebSocket();
                    } else {
                        self.$message.error(res.message);
                        self.flag = false;
                    }
                });
            }
        },
        watch: {
            'websockMsg': {
                handler: function(newval , oldval) {
                    if (newval.type == 4) {
                        this.flag = true;
                    }else if(newval.type == 8){
                        this.flag = false
                    }
                },
                deep: true
            }
        }
    };
</script>

<style lang="scss" scoped>

</style>
